package logic.bean;

import java.io.Serializable;

import logic.util.Util;

/**
 * 专区内容项的对象bean
 * 
 * @author zouqp
 * @date 2015-01-15
 */
public class RegionContentItemBean implements Serializable {
	private static final long serialVersionUID = -1782469404657833866L;
    //	private int     type; //1为单条资讯，2为多条资讯(卡片式的)，3为单本书籍, 4为图集，5 为音频， 6为视频，
	private long moduleContentId;
	private String type;//基础类型 1=单条资讯 2=多条资讯 3=音频 4=视频 5=图集 6=单本书籍 7多本书籍
	private String dataJson;
	private long publishTime;
	
	private SingleNews       singleNews;
	private MultiNews        mutilNews;
	private ImageCollection  imageSet ;
	private SingleBook       singleBook;
	private AudioAndVideo    audioNews;
	private AudioAndVideo    videoNews;
	
	public long getModuleContentId() {
		return moduleContentId;
	}
	public void setModuleContentId(long moduleContentId) {
		this.moduleContentId = moduleContentId;
	}
	
	public String getType() {
		return type;
	}
	
	public void setType(String type) {
		this.type = type;
	}
	
	public String getDataJson() {
		return dataJson;
	}
	public void setDataJson(String dataJson) {
		this.dataJson = dataJson;
	}
	
	public long getPublishTime() {
		return publishTime;
	}
	public void setPublishTime(long publishTime) {
		this.publishTime = publishTime;
	}
	
	public SingleNews getSingleNews() {
		if( !type.equalsIgnoreCase("1")) return null;
		if(singleNews != null ) return singleNews;
		singleNews = (SingleNews)Util.jsonStringToObject(getDataJson(), SingleNews.class);
		return singleNews;
	}
	public void setSingleNews(SingleNews singleNews) {
		this.singleNews = singleNews;
	}
	
	public MultiNews getMutilNews() {
		if( !type.equalsIgnoreCase("2")) return null;
		if(mutilNews != null ) return mutilNews;
		mutilNews = (MultiNews)Util.jsonStringToObject(getDataJson(), MultiNews.class);
		return mutilNews;
	}
	public void setMutilNews(MultiNews mutilNews) {
		this.mutilNews = mutilNews;
	}
	
	public ImageCollection getImageSet() {
		if( !type.equalsIgnoreCase("5")) return null;
		if(imageSet != null ) return imageSet;
		imageSet = (ImageCollection)Util.jsonStringToObject(getDataJson(), ImageCollection.class);
		return imageSet;
	}
	public void setImageSet(ImageCollection imageSet) {
		this.imageSet = imageSet;
	}
	
	public SingleBook getSingleBook() {
		if( !type.equalsIgnoreCase("6")) return null;
		if(singleBook != null ) return singleBook;
		singleBook = (SingleBook)Util.jsonStringToObject(getDataJson(), SingleBook.class);
		return singleBook;
	}
	public void setSingleBook(SingleBook singleBook) {
		this.singleBook = singleBook;
	}
	
	public AudioAndVideo getAudioNews() {
		if( !type.equalsIgnoreCase("3")) return null;
		if(audioNews != null ) return audioNews;
		audioNews = (AudioAndVideo)Util.jsonStringToObject(getDataJson(), AudioAndVideo.class);
		return audioNews;
	}
	public void setAudioNews(AudioAndVideo audioNews) {
		this.audioNews = audioNews;
	}
	
	public AudioAndVideo getVideoNews() {
		if( !type.equalsIgnoreCase("4")) return null;
		if(videoNews != null ) return videoNews;
		videoNews = (AudioAndVideo)Util.jsonStringToObject(getDataJson(), AudioAndVideo.class);
		return videoNews;
	}
	public void setVideoNews(AudioAndVideo videoNews) {
		this.videoNews = videoNews;
	}
    
    public static RegionContentItemBean generateContentItem( ) {
    	int type = (int)((Math.random() + 0.2) * 6);
    	int random = (int)(Math.random() * 1000);
    	RegionContentItemBean contentItem = new RegionContentItemBean() ;
    	contentItem.setModuleContentId(random);
    	contentItem.setType(type+ "");
    	return contentItem;
    }
}
